﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

using System.Linq;
using System.Text;

using System.Runtime.InteropServices; // Incluir
namespace testeEasyLab_c.Basica
{
    public class EasyLab_c
    {

        [DllImport("Easy_Lab.dll")] // declaração funções dll
        public static extern int SearchDevices(out byte ndevs);
        [DllImport("Easy_Lab.dll")]
        public static extern int SetPortDirections(byte dev, int ddr);
        [DllImport("Easy_Lab.dll")]
        public static extern int SetOutputPorts(byte dev, int DataOut);
        [DllImport("Easy_Lab.dll")]
        public static extern int GetInPorts(byte dev, out int DataIn);
        [DllImport("Easy_Lab.dll")]
        public static extern int SetPWM(byte dev, byte div, int Duty);
        [DllImport("Easy_Lab.dll")]
        public static extern int Icen(byte dev, int Freq);
        [DllImport("Easy_Lab.dll")]
        public static extern int DoGetIcp(byte dev, out int Freq, out int Count);
        
        private bool estado;

        public bool Estado
        {
            get { return estado; }
            set { estado = value; }
        }


       



        public EasyLab_c() { }

        public int detectarDispositivo() 
        {
            
            byte ndips;
            int qtdDispositivo;

            qtdDispositivo = SearchDevices(out ndips);

            return qtdDispositivo;
           
        }
        public void acionarRele(int porta)
        {
            int bPorta = (int) Math.Pow(2,porta);

            Console.WriteLine(bPorta);

            
            SetPortDirections(0,bPorta);// Seta a porta como saida
            SetOutputPorts(0,bPorta); // Liga a porta
           
        }

        public int acionaFrequencimetro()
        {
            int freq;
            int count;

            Icen(0,0);
            DoGetIcp(0, out freq, out count);

            return freq;
        }

        public void desligar()
        {

           
            SetOutputPorts(0, 0);
        }

        public int verificaEstado()
        {
            int estado;
            
                GetInPorts(0, out estado);
                return estado;
        }

       

    }
}
